<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>report sms</title>
        <link href="../../script/seminar.css" rel="stylesheet"/>
        <script type="text/javascript" src="../../js/jquery.js"></script>
        <script type="text/javascript" src="../../js/jquery.validate.min.js"></script>
        <script type="text/javascript" src="../../js/script.js"></script>
        <script type="text/javascript">
            function fnChangeTujuan() {
                var vIdxTujuan = document.reportSmsForm.slctTujuan.selectedIndex;
                var vTujuan = document.getElementById("slctTujuan")[vIdxTujuan].value;
                if (vTujuan == '2') {
                    // reviewer, set pengirim jadi administrator
                    document.getElementById("slctPengirim").value = '2';
                    document.getElementById("slctPengirim").disabled = true;
                    // reviewer, set sms jadi permintaan review
                    document.getElementById("slctSMS").value = '6';
                    document.getElementById("slctSMS").disabled = true;
                } else {
                    document.getElementById("slctPengirim").disabled = false;
                    document.getElementById("slctSMS").disabled = false;
                }
            }
            function fnChangeSMS() {
                var vIdxSMS = document.reportSmsForm.slctSMS.selectedIndex;
                var vSMS = document.getElementById("slctSMS")[vIdxSMS].value;
                if (vSMS == '6') {
                    // permintaan review, pengirim admin
                    document.getElementById("slctPengirim").value = '2';
                    document.getElementById("slctPengirim").disabled = true;
                    // permintaan review, tujuan reviewer
                    document.getElementById("slctTujuan").value = '1';
                    document.getElementById("slctTujuan").disabled = true;
                } else if ((vSMS == '3') || (vSMS == '4') || (vSMS == '5')) {
                    // permintaan naskah / tambahan, tujuan pembicara
                    document.getElementById("slctTujuan").value = '1';
                    document.getElementById("slctTujuan").disabled = true;
                } else if ((vSMS == '1') || (vSMS == '2')) {
                    // persetujuan / penolakan, tujuan pembicara
                    document.getElementById("slctTujuan").value = '1';
                    document.getElementById("slctTujuan").disabled = true;
                    // persetujuan / penolakan, pengirim admin
                    document.getElementById("slctPengirim").value = '2';
                    document.getElementById("slctPengirim").disabled = true;
                }
            }
            function fnCari() {
                // tujuan
                var vIdxTujuan = document.reportSmsForm.slctTujuan.selectedIndex;
                var vTujuan = document.getElementById("slctTujuan")[vIdxTujuan].value;
                // pengirim
                var vIdxPengirm = document.reportSmsForm.slctPengirim.selectedIndex;
                var vPengirim = document.getElementById("slctPengirim")[vIdxPengirm].value;
                // sms
                var vIdxSMS = document.reportSmsForm.slctSMS.selectedIndex;
                var vSMS = document.getElementById("slctSMS")[vIdxSMS].value;
                
                document.reportSmsForm.hidTujuan.value = vTujuan;
                document.reportSmsForm.hidPengirim.value = vPengirim;
                document.reportSmsForm.hidSMS.value = vSMS;
                
                document.reportSmsForm.method = 'POST';
                document.reportSmsForm.action = '../../logic/getReportSMS.php';
                document.reportSmsForm.submit();
            }
        </script>
    </head>
    <body>
        <?php
        include("../../utility/connection.php");
        include("../../utility/general.php");
        include("../../model/mSMS.php");
        
        session_start();
        if (isset($_SESSION['arrResult'])) {
            $arrResult = $_SESSION['arrResult'];
            
            $result = fnGetReportSMS();
            $Tujuan = '';
            $Pengirim = '';
            $Sms = '';        
            if (isset($_SESSION['reportSMS'])) {
                if (isset($_SESSION['Tujuan'])) {
                    $Tujuan = $_SESSION['Tujuan'];
                }
                if (isset($_SESSION['Pengirim'])) {
                    $Pengirim = $_SESSION['Pengirim'];
                }
                if (isset($_SESSION['Sms'])) {
                    $Sms = $_SESSION['Sms'];
                }
                $result = fnGetReportSMSByAll($Tujuan, $Pengirim, $Sms);
            }
                                        
        ?>
        <form name="reportSmsForm" id="reportSmsForm">
            <input type="hidden" name="hidTujuan" id="hidTujuan">
            <input type="hidden" name="hidPengirim" id="hidPengirim">
            <input type="hidden" name="hidSMS" id="hidSMS">
        <table border="0" width="100%" height="100%">
            <tr valign="middle">
                <td align="center">
                    
                    <table width="1024" border="0" cellpadding="2" cellspacing="0">
                        <tr>
                            <td>
                                <table>
                                    <tr>
                                        <td>Tujuan</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td>
                                            <select name="slctTujuan" id="slctTujuan" onchange="fnChangeTujuan()">
                                                <option value="0" <?php echo ($Tujuan == '0')? 'SELECTED':'' ?>>Semua&nbsp;Tujuan</option>
                                                <option value="1" <?php echo ($Tujuan == '1')? 'SELECTED':'' ?>>Pembicara</option>
                                                <option value="2" <?php echo ($Tujuan == '2')? 'SELECTED':'' ?>>Reviewer</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Pengirim</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td>
                                            <select name="slctPengirim" id="slctPengirim" onchange="fnChangePengirim()">
                                                <option value="0" <?php echo ($Pengirim == '0')? 'SELECTED':'' ?>>Semua&nbsp;Pengirim</option>
                                                <option value="1" <?php echo ($Pengirim == '1')? 'SELECTED':'' ?>>Reviewer</option>
                                                <option value="2" <?php echo ($Pengirim == '2')? 'SELECTED':'' ?>>Admin Aplikasi</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Jenis SMS</td>
                                        <td>&nbsp;:&nbsp;</td>
                                        <td>
                                            <select name="slctSMS" id="slctSMS" onchange="fnChangeSMS()">
                                                <option value="0">Semua&nbsp;Jenis</option>
                                                <?php
                                                $resultSms = fnGetMasterSMS();
                                                if ($resultSms) {
                                                    while($rowSms = mysql_fetch_row($resultSms)){
                                                ?>
                                                <option value="<?php echo $rowSms[1] ?>" <?php echo ($Sms == $rowSms[1])? 'SELECTED':'' ?>><?php echo $rowSms[2] ?></option>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <button type="button" name="btCari" id="btCari" onclick="fnCari()">Cari</button>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr class="tbl-body">
                            <td>
                                <table width="100%" height="100%" border="1" cellpadding="5" cellspacing="0">
                                    <tr class="tbl-header">
                                        <td>No</td>
                                        <td>Tgl</td>
                                        <td>No Penerima</td>
                                        <td>Nama Penerima</td>
                                        <td>Tipe SMS</td>
                                        <td>No Pengirim</td>
                                        <td>Nama Pengirim</td>
                                    </tr>
                                    <?php
                                        if ($result) {
                                            while($row = mysql_fetch_row($result)){
                                                $no = $row[0];
                                                
                                                $tgl = $row[1];
                                                $digitTgl = substr($tgl, 8, 2);
                                                $digitBulan = fnConvertMonth(substr($tgl, 5, 2));
                                                $digitTahun = substr($tgl, 0, 4);
                                                $Tanggal = $digitTgl . ' ' . $digitBulan . ' ' . $digitTahun;

                                                $no_penerima = $row[2];
                                                $nama_penerima = $row[3];
                                                $isi_sms = $row[4];
                                                $nama_pengirim = $row[5];
                                                $no_pengirim = $row[6];
                                                $kode_sms = $row[7];
                                                
                                                $kode_alasan_sms = $row[8];
                                                $alasan_sms = $row[9];
                                    ?>
                                    <tr>
                                        <?php 
                                        ?>
                                        <td rowspan="2"><?php echo $no ?></td>
                                        <td><?php echo $Tanggal ?></td>
                                        <td><?php echo $no_penerima ?></td>
                                        <td><?php echo $nama_penerima ?></td>
                                        <td><?php echo $alasan_sms ?></td>
                                        <td><?php echo $no_pengirim ?></td>
                                        <td><?php echo $nama_pengirim ?></td>
                                        <?php 
                                        ?>
                                    </tr>
                                    <tr>
                                        <td colspan="7"><?php echo $isi_sms ?></td>
                                    </tr>
                                    <?php
                                            }
                                        }
                                    ?>
                                </table>
                            </td>
                        </tr>
                    </table>
                    
                </td>
            </tr>
        </table>
        </form>
        <?php
        }
        ?>
    </body>
</html>
